package com.xlhj.boot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author: liucaijing
 * @description: FanoutListener
 * @date: 2021/10/20 9:04
 */
@Component
public class FanoutListener {

    private static final String FANOUT_QUEUE_NAME_A = "fanout-queue-A";
    private static final String FANOUT_QUEUE_NAME_B = "fanout-queue-B";
    private static final String FANOUT_QUEUE_NAME_C = "fanout-queue-C";
    private static Logger logger = LoggerFactory.getLogger(FanoutListener.class);

    @RabbitListener(queues = FANOUT_QUEUE_NAME_A)
    public void receiveMsgA(Message message) {
        String msg = new String(message.getBody());
        logger.info("接收到队列fanout.queueA消息：{}", msg);
    }

    @RabbitListener(queues = FANOUT_QUEUE_NAME_B)
    public void receiveMsgB(Message message) {
        String msg = new String(message.getBody());
        logger.info("接收到队列fanout.queueB消息：{}", msg);
    }

    @RabbitListener(queues = FANOUT_QUEUE_NAME_C)
    public void receiveMsgC(Message message) {
        String msg = new String(message.getBody());
        logger.info("接收到队列fanout.queueC消息：{}", msg);
    }
}
